import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  NaiveUiResolver
} from 'unplugin-vue-components/resolvers'
export default defineConfig({
  resolve: {
    alias: {
      '@/': `${resolve(__dirname, 'src')}/`
    }
  },
  plugins: [
    vue(),
    Components({
      // 指定组件位置，默认是src/components
      dirs: ['src/components'],
      extensions: ['vue'],
      // 配置文件生成位置
      dts: 'presets/components.d.ts',
      resolvers: [
        NaiveUiResolver()
      ]
    }),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'presets/auto-import.d.ts'
    })
  ],
  server: {
    proxy: {
      '/api': {
        target:'http://localhost:8001',
        changeOrigin: true,
        rewrite: (path) => {
          return path.replace(/^\/api/, '')
        }
      }
    }
  }
})
